<template>
  <div class="app-container">
    <u-page title="优惠券分组">
      <div slot="header">
        <el-button type="primary" icon="el-icon-plus" @click="hdlOpen">
          {{ textMap['create'] }}
        </el-button>
      </div>
      <u-filtered>
        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="分组名称" prop="groupName">
            <el-input v-model="listQuery.groupName" placeholder="请输入分组名称" clearable style="width: 170px" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>
      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
        <template v-slot:right>
          <el-table-column label="操作" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="hdlEdit(row)">编辑</el-button>
              <el-button type="text" @click="hdlDelete(row.id, row.groupName)">删除</el-button>
            </template>
          </el-table-column>
        </template>
      </u-table>
    </u-page>
    <u-dialog :title="textMap[dialogStatus]" :show.sync="dialogFormVisible" width="600px" @confirm="dialogStatus==='create'? hdlCreate():hdlUpdate()">
      <el-form ref="dialogForm" :model="dataForm" :rules="rules" label-width="100px">
        <el-form-item label="分组名称" prop="groupName">
          <el-input v-model="dataForm.groupName" placeholder="请输入分组名称" clearable maxlength="20" show-word-limit />
        </el-form-item>
        <el-form-item label="备注" prop="note" class="left-align-hide">
          <el-input v-model="dataForm.note" type="textarea" :rows="3" placeholder="请输入内容" maxlength="60" show-word-limit />
        </el-form-item>
      </el-form>
    </u-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      api: this.$u.api.MarketCouponGroup,
      /** 新建优惠券分组 **/
      dataForm: {},
      rules: {
        groupName: [
          { required: true, message: '优惠券分组名称必填', trigger: 'blur' }
        ]
      },
      /** 优惠券分组列表 **/
      listQuery: {
        page: 1,
        pageSize: 10,
        totalCount: 1,
        groupName: ''
      },
      textMap: {
        update: '编辑分组',
        create: '新增分组'
      },
      dialogFormVisible: false,
      dialogStatus: '',
      // 表格
      columns: [
        {
          prop: 'groupName',
          label: '分组名称'
        },
        {
          prop: 'note',
          label: '备注'
        },
        {
          prop: 'createdAt',
          label: '创建时间',
          sortable: true,
          timestamp: true
        }
      ],
      listLoading: false,
      list: [],
      listOptions: {
        mutiSelect: true,
        stripe: true
      }
    }
  },
  created() {
    this.hdlList()
  }

}
</script>

<style lang="scss" scoped>
.app-container{
  .disabled {
    ::v-deep{
      .el-input{
        width: 140px;
      }
    }
  }
}
/* 表单label 左对齐*/
::v-deep .left-align-show .el-form-item__label::before{
  content: "*";
  color: #ff4949;
  margin-right: 4px;
}
/* 表单label 左对齐*/
::v-deep .left-align-hide .el-form-item__label::before{
  content: "*";
  color: transparent;
  margin-right: 4px;
}
</style>

